package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Recibes;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class RecibesPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Recibes> list;

public RecibesPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Recibes recibes ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into recibes(idrecibo,fecha,id,tipoid,anulado,exonerado,moroso,idmunicipio,totalpagado,totalexonerado,idexonerado,idusuario,tiporecibo,cedulatesoreroauxiliar,idreciboauxiliar)  values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,recibes.getIdrecibo());
        pinsert.setDate(2,recibes.getFecha());
        pinsert.setString(3,recibes.getId());
        pinsert.setString(4,recibes.getTipoid());
        pinsert.setString(5,recibes.getAnulado());
        pinsert.setString(6,recibes.getExonerado());
        pinsert.setString(7,recibes.getMoroso());
        pinsert.setString(8,recibes.getIdmunicipio());
        pinsert.setDouble(9,recibes.getTotalpagado());
        pinsert.setDouble(10,recibes.getTotalexonerado());
        pinsert.setString(11,recibes.getIdexonerado());
        pinsert.setString(12,recibes.getIdusuario());
        pinsert.setString(13,recibes.getTiporecibo());
        pinsert.setString(14,recibes.getCedulatesoreroauxiliar());
        pinsert.setInt(15,recibes.getIdreciboauxiliar());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Recibes recibes ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update recibes set  idrecibo=?, fecha=?, id=?, tipoid=?, anulado=?, exonerado=?, moroso=?, idmunicipio=?, totalpagado=?, totalexonerado=?, idexonerado=?, idusuario=?, tiporecibo=?, cedulatesoreroauxiliar=?, idreciboauxiliar=?  where  idrecibo ='"+recibes.getIdrecibo()+"' and  idmunicipio ='"+recibes.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,recibes.getIdrecibo());
pupdate.setDate(2,recibes.getFecha());
pupdate.setString(3,recibes.getId());
pupdate.setString(4,recibes.getTipoid());
pupdate.setString(5,recibes.getAnulado());
pupdate.setString(6,recibes.getExonerado());
pupdate.setString(7,recibes.getMoroso());
pupdate.setString(8,recibes.getIdmunicipio());
pupdate.setDouble(9,recibes.getTotalpagado());
pupdate.setDouble(10,recibes.getTotalexonerado());
pupdate.setString(11,recibes.getIdexonerado());
pupdate.setString(12,recibes.getIdusuario());
pupdate.setString(13,recibes.getTiporecibo());
pupdate.setString(14,recibes.getCedulatesoreroauxiliar());
pupdate.setInt(15,recibes.getIdreciboauxiliar());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  recibes set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Recibes recibes_old , Recibes recibes) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update recibes set  idrecibo=? ,  idmunicipio=?  where  idrecibo ='"+recibes_old.getIdrecibo()+"' and  idmunicipio ='"+recibes_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,recibes.getIdrecibo());pupdate.setString(8,recibes.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Recibes recibes ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from recibes  where  idrecibo = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,recibes.getIdrecibo());
pdelete.setString(8,recibes.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from recibes where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from recibes  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Recibes recibes) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from recibes where idrecibo='"+recibes.getIdrecibo()+"' and idmunicipio='"+recibes.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Recibes findByPrimaryKey(Recibes recibes) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from recibes where idrecibo='"+recibes.getIdrecibo()+"' and idmunicipio='"+recibes.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            recibes.setIdrecibo(rs.getInt("idrecibo"));
recibes.setFecha(rs.getDate("fecha"));
recibes.setId(rs.getString("id"));
recibes.setTipoid(rs.getString("tipoid"));
recibes.setAnulado(rs.getString("anulado"));
recibes.setExonerado(rs.getString("exonerado"));
recibes.setMoroso(rs.getString("moroso"));
recibes.setIdmunicipio(rs.getString("idmunicipio"));
recibes.setTotalpagado(rs.getDouble("totalpagado"));
recibes.setTotalexonerado(rs.getDouble("totalexonerado"));
recibes.setIdexonerado(rs.getString("idexonerado"));
recibes.setIdusuario(rs.getString("idusuario"));
recibes.setTiporecibo(rs.getString("tiporecibo"));
recibes.setCedulatesoreroauxiliar(rs.getString("cedulatesoreroauxiliar"));
recibes.setIdreciboauxiliar(rs.getInt("idreciboauxiliar"));
    }
    rs.close();
    psquery.close();
 return recibes;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdrecibo()
*/

public static List<Recibes> findByIdrecibo(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where idrecibo='"+recibes.getIdrecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Recibes> findByFecha(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where fecha='"+recibes.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findById()
*/

public static List<Recibes> findById(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where id='"+recibes.getId()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoid()
*/

public static List<Recibes> findByTipoid(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where tipoid='"+recibes.getTipoid()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByAnulado()
*/

public static List<Recibes> findByAnulado(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where anulado='"+recibes.getAnulado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByExonerado()
*/

public static List<Recibes> findByExonerado(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where exonerado='"+recibes.getExonerado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMoroso()
*/

public static List<Recibes> findByMoroso(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where moroso='"+recibes.getMoroso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Recibes> findByIdmunicipio(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where idmunicipio='"+recibes.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTotalpagado()
*/

public static List<Recibes> findByTotalpagado(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where totalpagado='"+recibes.getTotalpagado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTotalexonerado()
*/

public static List<Recibes> findByTotalexonerado(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where totalexonerado='"+recibes.getTotalexonerado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdexonerado()
*/

public static List<Recibes> findByIdexonerado(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where idexonerado='"+recibes.getIdexonerado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdusuario()
*/

public static List<Recibes> findByIdusuario(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where idusuario='"+recibes.getIdusuario()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTiporecibo()
*/

public static List<Recibes> findByTiporecibo(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where tiporecibo='"+recibes.getTiporecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCedulatesoreroauxiliar()
*/

public static List<Recibes> findByCedulatesoreroauxiliar(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where cedulatesoreroauxiliar='"+recibes.getCedulatesoreroauxiliar()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdreciboauxiliar()
*/

public static List<Recibes> findByIdreciboauxiliar(Recibes recibes,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
      String sql = "select * from recibes where idreciboauxiliar='"+recibes.getIdreciboauxiliar()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Recibes> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Recibes>();
  String sql = "select * from recibes";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from recibes";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from recibes where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from recibes";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from recibes where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Recibes> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Recibes>();
  String sql = "select * from recibes where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Recibes> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Recibes>();
  String sql = "select * from recibes";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "recibes" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Recibes recibes2 = new Recibes(
         rs.getInt("idrecibo"),rs.getDate("fecha"),rs.getString("id"),rs.getString("tipoid"),rs.getString("anulado"),rs.getString("exonerado"),rs.getString("moroso"),rs.getString("idmunicipio"),rs.getDouble("totalpagado"),rs.getDouble("totalexonerado"),rs.getString("idexonerado"),rs.getString("idusuario"),rs.getString("tiporecibo"),rs.getString("cedulatesoreroauxiliar"),rs.getInt("idreciboauxiliar"));
            
            
       list.add(recibes2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
